package com.zisu.aradvertising.service.impl;


import com.zisu.aradvertising.pojo.Product;
import com.zisu.aradvertising.repository.DaoProduct;
import com.zisu.aradvertising.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

//尤其注意当涉及到删除的时候，要加上@Transactional
@Transactional
@Service
public class ProductServiceImpl implements ProductService {
    //实例化抽象类
    @Resource
    private DaoProduct daoProduct;

    @Override
    //实现返回所有产品业务逻辑
    public List<Product> findallbyaidService(int aid)
    {
        List<Product> list=daoProduct.findAllByAid(aid);
        if(list.size()==0)return null;
        else return list;
    }
    @Override
    //实现返回一个产品业务逻辑
    public Product findbypidService(int pid)
    {
        Product product=daoProduct.findByPid(pid);
        return product;
    }
    @Override
    //新增一个产品
    public Product addService(Product product){
        return daoProduct.save(product);
    }

    @Override
    //删除一个产品
    public void deleteService(int pid){
        daoProduct.deleteByPid(pid);
    }


}
